package com.yc.dygang.web;

import com.yc.dygang.dao.MovieDao;
import com.yc.dygang.util.Utils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "SearchServlet", value = "/search.s")
public class SearchServlet extends HttpServlet {

    // 创建 电影dao 对象
    private MovieDao movieDao = new MovieDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String category = request.getParameter("category");
        String page = request.getParameter("page");

        if(name==null || name.equals("null")){
            name = "";
        }

        if (page == null) {
            page = "1";
        }
        Map<String, Object> p = movieDao.selectByNameAndCategory(name, category, page);
        Utils.toJson(p, response);
    }

}
